import httplib
import urllib
import json
import hashlib
import hmac
 
# Replace these with your own API key data
BTC_api_key = "GFCC0DUH-7BK6OJK4-XRLLL98U-24WC7WUA-0Q4W2IZO"
BTC_api_secret = "e4466199e94af170240325dfed9aa1d62d9e26253dc087991a29656d884a0c62"
# Come up with your own method for choosing an incrementing nonce
nonce = 13

# method name and nonce go into the POST parameters
params = {"method":"getInfo",
          "nonce": nonce}
params = urllib.urlencode(params)
 
# Hash the params string to produce the Sign header value
H = hmac.new(BTC_api_secret, digestmod=hashlib.sha512)
H.update(params)
sign = H.hexdigest()
 
headers = {"Content-type": "application/x-www-form-urlencoded",
                   "Key":BTC_api_key,
                   "Sign":sign}
conn = httplib.HTTPSConnection("btc-e.com")
conn.request("POST", "/tapi", params, headers)
response = conn.getresponse()
 
print response.status, response.reason
print json.load(response)
 
conn.close()